package com.mazong.serveresaa.service.impl;

import com.mazong.serveresaa.pojo.TbArticle;
import com.mazong.serveresaa.repo.MyElasticRepository;
import com.mazong.serveresaa.service.IElasticService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.stereotype.Service;

import java.util.Iterator;
import java.util.List;

@Service("elasticService")
public class ElasticServiceImpl implements IElasticService {

    @Autowired
    private ElasticsearchRestTemplate elasticsearchTemplate;

    @Autowired
    private MyElasticRepository elasticRepository;

    private Pageable pageable = PageRequest.of(0,10);

    @Override
    public void createIndex() {
        elasticsearchTemplate.createIndex(TbArticle.class);
    }

    @Override
    public void deleteIndex(String index) {
        elasticsearchTemplate.deleteIndex(index);
    }

    @Override
    public void save(TbArticle docBean) {
        elasticRepository.save(docBean);
    }

    @Override
    public void saveAll(List<TbArticle> list) {
        elasticRepository.saveAll(list);
    }

    @Override
    public Iterator<TbArticle> findAll() {
        return elasticRepository.findAll().iterator();
    }

}
